<!DOCTYPE html>
<#assign ctxPath = request.contextPath />
<html>

<head>
    <title>注册</title>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${ctxPath}/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/css/login.css" media="all">
    <style>
        body {
            background-position: center 110px;
            background-repeat: no-repeat;
            background-size: 100%;
            background-color: #f0f2f5;
        }

        .login-header {
            color: rgba(0, 0, 0, .85) !important;
        }

        .login-footer {
            color: rgba(0, 0, 0, 0.7) !important;
        }

        .login-footer a {
            color: rgba(0, 0, 0, 0.7) !important;
        }

        .login-footer a:hover {
            color: rgba(0, 0, 0, 0.4) !important;
        }
    </style>
</head>

<body>
<div class="login-wrapper">

    <div class=" login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                <i class="layui-icon layui-icon-engine"></i>&nbsp;&nbsp;用户注册
            </div>
            <div class="layui-card-body layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label">账号</label>
                    <div class="layui-input-block">
                        <input name="username" type="text" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input name="password" type="password" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">重复密码</label>
                    <div class="layui-input-block">
                        <input name="repass" type="password" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-block">
                        <input name="phone" type="text" lay-verify="required" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button lay-filter="LAY-user-reg-submit" class="layui-btn layui-btn-fluid" lay-submit>注 册</button>
                </div>
            </div>
        </div>
    </div>

    <div class="login-footer">
    </div>
</div>

<script type="text/javascript" src="${ctxPath}/layui/layui.js"></script>
<!--<script type="text/javascript" src="${ctxPath}/assets/common/js/common.js"></script>-->
<script>
    layui.use(['layer', 'form'], function () {
        var $ = layui.jquery
            , setter = layui.setter
            , admin = layui.admin
            , form = layui.form
            , router = layui.router();

        form.render();

        form.on('submit(LAY-user-reg-submit)', function (obj) {
            var field = obj.field;

            //确认密码
            if (field.password !== field.repass) {
                return layer.msg('两次密码输入不一致');
            }

            //请求接口
            $.post(
                '/users/registry'
                , {
                    userName: field.username,
                    passWord: field.password,
                    tel: field.phone
                }
                , function (res) {
                    console.log(res.success == true)
                    if (res.success == true) {
                        layer.msg('注册成功', {
                            offset: '15px'
                            , icon: 1
                            , time: 2000
                        }, function () {
                            location.href = '/'; //跳转到登入页
                        });

                    } else {
                        layer.msg(res.message)
                    }
                }
            );

            return false;
        });


    });
</script>
</body>
</html>
